package com.eoner.baselibrary.base;

import android.content.Context;

import com.eoner.baselib.utils.notify.RxManager;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * 作者：sean
 * 创建时间：2017/6/23 10:54
 * 功能说明：Presenter基类
 */

public abstract class BasePresenter<T> {
    public Context context;
    public T mView;
    public RxManager mRxManager = new RxManager();

    public void setVM(T v) {
        this.mView = v;
        this.onStart();
    }

    public abstract void onStart();

    //添加线程管理并订阅
    public Disposable toSubscribe(Observable observable, Consumer next, Consumer error){
        return  observable.subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(next,error);
    }

    public void onDestroy() {
        if (mRxManager != null) {
            mRxManager.clear();
            mRxManager = null;
        }
    }
}
